#pragma once

#include <memory>
#include <QObject>

class QString;
class QByteArray;
class QIODevice;

class ISimpleChannel : public QObject
{
    Q_OBJECT 

public:
    virtual bool       Open()                       = 0;
    virtual bool       IsOpened()                   = 0;
    virtual void       Reset()                      = 0;
    virtual void       Close()                      = 0;

    virtual unsigned   DataAvailable()              = 0;
    virtual QString    LastError()                  = 0;
    virtual QString    Info()                       = 0;

    virtual QByteArray Receive(unsigned size)       = 0;
    virtual unsigned   Send(const QByteArray& data) = 0;

public slots:
    void HasData();

signals:
    void disconnected();
    void dataNotification(const QByteArray& data);
    void keyValueSignal(const QString& key, const QString& value);
};

typedef std::tr1::shared_ptr<ISimpleChannel> ISimpleChannelPtr;

unsigned ForceWrite(QIODevice* io, const QByteArray& data);